From 5cd8e0f7f18cdd6de6482b9cdae14bd5b0819c73 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Thu, 18 Apr 2019 02:18:42 +0200 Subject: [PATCH] testsuite: Add theme-validate test The test just loads all of GTK's themes and makes sure they cause no errors or warnings from the CSS parser. --- testsuite/gtk/meson.build | 1 + testsuite/gtk/theme-validate.c | 70 ++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 testsuite/gtk/theme-validate.c diff --git a/testsuite/gtk/meson.build b/testsuite/gtk/meson.build index 97e5f47fce..246078c400 100644 --- a/testsuite/gtk/meson.build +++ b/testsuite/gtk/meson.build @@ -52,6 +52,7 @@ tests = [ ['templates'], ['textbuffer'], ['textiter'], + ['theme-validate'], ['transform'], ['treelistmodel'], ['treemodel', ['treemodel.c', 'liststore.c', 'treestore.c', 'filtermodel.c', diff --git a/testsuite/gtk/theme-validate.c b/testsuite/gtk/theme-validate.c new file mode 100644 index 0000000000..e2e51e5852 --- /dev/null +++ b/testsuite/gtk/theme-validate.c @@ -0,0 +1,70 @@ +#include + +typedef struct _Theme Theme; + +struct _Theme +{ + const char *name; + const char *variant; +}; + +static void +theme_parsing_error (GtkCssProvider *provider, + GtkCssSection *section, + const GError *error, + gpointer unused) +{ + char *s = gtk_css_section_to_string (section); + + g_test_message ("Theme parsing error: %s: %s", + s, + error->message); + + g_free (s); + + g_test_fail (); +} + +static void +test_theme (gconstpointer data) +{ + const Theme *theme = data; + GtkCssProvider *provider; + + provider = gtk_css_provider_new (); + g_signal_connect (provider, "parsing-error", + G_CALLBACK (theme_parsing_error), NULL); + gtk_css_provider_load_named (provider, theme->name, theme->variant); + g_object_unref (provider); +} + +int +main (int argc, char *argv[]) +{ + const Theme themes[] = { + { "Adwaita", NULL }, + { "Adwaita", "dark" }, + { "HighContrast", NULL }, + { "HighContrast", "dark" } + }; + guint i; + + gtk_init (); + g_test_init (&argc, &argv, NULL); + + for (i = 0; i < G_N_ELEMENTS (themes); i++) + { + char *testname; + + if (themes[i].variant == NULL) + testname = g_strdup_printf ("/theme-validate/%s", themes[i].name); + else + testname = g_strdup_printf ("/theme-validate/%s-%s", themes[i].name, themes[i].variant); + + g_test_add_data_func (testname, &themes[i], test_theme); + + g_free (testname); + } + + return g_test_run (); +} -- 2.30.2